<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="timer">4</div>
    <script>
        var num = 4;
        function show(){
            setTimeout(() => {
                num--;
                if(num>=0){
                    document.getElementById("timer").innerHTML = num;
                    console.log(num);
                    show();
                }
            }, 1000);
        }
        show();
    </script>
</body>
</html>